﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
 
public enum LOGCOLOR
{
	BLUE,
	RED,
	YELLOW,
	CYAN,
	BLACK,
	BROWN,
	DARKBLUE,
	GREEN,
	GREY,
	LIGHTBLUE,
	MAGNETA,
	LIME,
	MAROON,
	NAVY,
	OLIVE,
	ORANGE,
	PURPLE,
	SLIVER,
	TEAL,
	WHITE
}

public class glog : MonoBehaviour {
	
    private float windowPosition = 0;//-440.0f;
    private int positionCheck = 2;
    private static string windowText = "";
    private Vector2 scrollViewVector = Vector2.zero;
    private GUIStyle debugBoxStyle;
	float buttonSizeMultipier = 1.0f;
    private float leftSide = 0.0f;
    private float debugWidth = 420.0f;
    public static bool debugIsOn = false;
	
	//for chat
	public bool chatboxOn = true;
    public List<string> messages = new List<string>();

    private int chatHeight = (int)140;
    private Vector2 scrollPos = Vector2.zero;
    private string chatInput = "";
    private float lastUnfocusTime = 0;
	
    public static void debug(string newString)
    {
//#if !UNITY_EDITOR
        windowText = newString + "\n" + windowText;
        UnityEngine.Debug.Log(newString);
//#endif
    }
	public static void debug(string newString, LOGCOLOR color)
	{
		windowText = newString + "\n" + windowText;
		UnityEngine.Debug.Log("<color="+color.ToString().ToLower()+">"+newString+"</color>");
	}
	
	void Start () {
        debugBoxStyle = new GUIStyle();
        debugBoxStyle.alignment = TextAnchor.UpperLeft;
        leftSide = 120; //Screen.width - debugWidth - 3;
		//buttonSizeMultipier;
		glog.debug ("Screen.width="+Screen.width+"  height="+Screen.height);
		buttonSizeMultipier = (float)Screen.width/800.0f;
    }

	/*
    void OnGUI () {

        if (debugIsOn) 
		{
            GUI.depth = 0;
            GUI.BeginGroup (new Rect(windowPosition, 40.0f, Screen.width, 200.0f));
                scrollViewVector = GUI.BeginScrollView (new Rect (0, 0.0f, Screen.width, Screen.height), scrollViewVector, new Rect (0.0f, 0.0f, Screen.width, Screen.height));
                GUI.Box (new Rect (0, 0.0f, Screen.width, Screen.height), windowText);
                GUI.EndScrollView();
            GUI.EndGroup ();

            if (GUI.Button(new Rect (Screen.width-75*buttonSizeMultipier ,30.0f*buttonSizeMultipier ,75.0f*buttonSizeMultipier ,40.0f* buttonSizeMultipier),"Clear")){
                windowText = "";
            }
			

			
			if(chatboxOn)
			{
		        GUI.SetNextControlName("");
		
		        GUILayout.BeginArea(new Rect(0, Screen.height - chatHeight, Screen.width, chatHeight));
		        
		        //Show scroll list of chat messages
		        scrollPos = GUILayout.BeginScrollView(scrollPos);
		        GUI.color = Color.red;
		        for (int i = messages.Count - 1; i >= 0; i--)
		        {
		            GUILayout.Label(messages[i]);
		        }
		        GUILayout.EndScrollView();
		        GUI.color = Color.white;
		
		        //Chat input
		        GUILayout.BeginHorizontal(); 
		        GUI.SetNextControlName("ChatField");
		    	chatInput = GUILayout.TextField(chatInput, GUILayout.MinWidth(200));
		       
		        if (Event.current.type == EventType.keyDown && Event.current.character == '\n'){
		            if (GUI.GetNameOfFocusedControl() == "ChatField")
		            {                
		                SendChat();
		                lastUnfocusTime = Time.time;
		                GUI.FocusControl("");
		                GUI.UnfocusWindow();
		            }
		            else
		            {
		                if (lastUnfocusTime < Time.time - 0.1f)
		                {
		                    GUI.FocusControl("ChatField");
		                }
		            }
		        }
		
		        //if (GUILayout.Button("SEND", GUILayout.Height(17)))
		         //   SendChat(PhotonTargets.All);
		        GUILayout.FlexibleSpace();
		        GUILayout.EndHorizontal();
		        GUILayout.EndArea();				
			}
        }
		
//		if (GUI.Button(new Rect (Screen.width-60*buttonSizeMultipier, 30*buttonSizeMultipier ,60.0f*buttonSizeMultipier,30.0f*buttonSizeMultipier), "Debug")){
//			debugIsOn = !debugIsOn;
//		}
//		if (GUI.Button(new Rect (Screen.width-60*buttonSizeMultipier, 60*buttonSizeMultipier ,60.0f*buttonSizeMultipier,25.0f*buttonSizeMultipier), "hide")){
//			CSceneManager.hideDebugUI = !CSceneManager.hideDebugUI;
//		}		


    }*/
	
	
    void SendChat()
    {
        if (chatInput != "")
        {
			glog.debug(chatInput);
			if(chatInput=="pop")
			{				
			//	CardManager.Instance.PopFirstCard(BoardManager.Instance.boardPerson_me.transform.position);
			}
			if(chatInput=="pd")
			{				
		//		CardManager.Instance.PushToDeactiveList();
			}
			if(chatInput=="pa")
			{				
		//		CardManager.Instance.PushToActiveQueue();
			}
			if(chatInput=="ac")
			{				
		//		CardManager.Instance.ActivateCard();
			}

            chatInput = "";
        }
    }	

}